<template>
  <div class="orderContainer">
    <div class="option">
      <el-button type="success" size="small" @click="addOrder()">新增订单</el-button>
      <!-- <el-button type="primary" size="small" @click="Refresh()">刷新</el-button> -->
    </div>
    <el-table :data="orderList" border style="width: 100%">
      <el-table-column prop="index" label="序号"></el-table-column>
      <!-- <el-table-column prop="orderNo" label="订单编号"></el-table-column> -->
      <!-- <el-table-column prop="name" label="运营商"></el-table-column> -->
      <!-- <el-table-column prop="exchangeCode" label="兑换码"></el-table-column> -->
      <!-- <el-table-column label="兑换图片">
        <template slot-scope="scope">
          <img :src="`http://www.jfqiandai.com/file${scope.row.exchangePic}`" style="width:80px">
        </template>
      </el-table-column>-->
      <el-table-column prop="integral" label="兑换积分"></el-table-column>
      <el-table-column prop="money" label="兑换金额"></el-table-column>
      <!-- <el-table-column prop="userId" label="用户id"></el-table-column> -->
      <el-table-column prop="userPhone" label="用户手机号码"></el-table-column>
      <!-- <el-table-column prop="createTime" label="创建时间"></el-table-column> -->
      <el-table-column fixed="right" label="操作" width="240">
        <template slot-scope="scope">
          <el-button @click="EditClick(scope.row)" type="primary" plain size="small">编辑</el-button>
          <el-button @click="DeleteClick(scope.row)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>

    <!-- 弹框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <div class="row">
        <span class="rowTil">兑换积分:</span>
        <el-input v-model="integral" placeholder="请输入兑换积分"></el-input>
      </div>

      <div class="row">
        <span class="rowTil">兑换金额:</span>
        <el-input v-model="money" placeholder="请输入兑换金额"></el-input>
      </div>

      <div class="row">
        <span class="rowTil">用户手机号码:</span>
        <el-input v-model="userPhone" placeholder="请输入用户手机号码"></el-input>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="isOkClick()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      val: 1, //当前多少页
      currentPage4: 1,
      changeCode: "", //搜索内容
      total: 0,
      status: 0,
      orderList: [],
      List: [],
      orderStatus: "", //订单状态
      flag: 0,
      dialogVisible: false,
      integral: "",
      money: "",
      userPhone: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //新增
    addOrder() {
      this.dialogVisible = true;
      this.flag = 1;
      this.integral = "";
      this.money = "";
      this.userPhone = "";
    },
    //编辑
    EditClick(row) {
      this.dialogVisible = true;
      this.flag = 2;
      this.editId = row.id;
      this.integral = row.integral;
      this.money = row.money;
      this.userPhone = row.userPhone;
    },

    //确定
    isOkClick() {
      if (this.flag == 1) {
        let url = "/order/addOne";
        let params = {
          isShow:1,
          integral: this.integral,
          money: this.money,
          userPhone: this.userPhone
        };
        this.httpPost(url, params, res => {
          if (res.code == 200) {
            this.dialogVisible = false;
            this.getList();
          }
        });
      } else {
        let url = "/order/edit";
        let params = {
          id: this.editId,
          integral: this.integral,
          money: this.money,
          userPhone: this.userPhone
        };
        this.httpPut(url, params, res => {
          if (res.code == 200) {
            this.dialogVisible = false;
            this.getList();
          }
        });
      }
    },

    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
    //刷新
    Refresh() {
      this.getList();
    },
    //查看
    // handleClick(row) {
    //   let id = row.id;
    //   this.$router.push("/checkOrder?id=" + id);
    // },
    //删除
    DeleteClick(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let url = "/order/edit";
          let params = {
            id: row.id,
            status: 1
          };
          this.httpPut(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功"
              });
              this.dialogVisible = false;
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //查询订单 + 搜索订单
    getList() {
      let url = "/order/findList";
      let params = {
        orderStatus: this.orderStatus,
        exchangeCode: this.changeCode,
        pageNum: this.val,
        show: 1,
        pageSize: "10"
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.orderList = res.data.list;
          this.total = res.data.total;
          this.orderList.forEach((element, i) => {
            this.orderList[i].index = (this.val - 1) * 10 + i + 1;
          });
        } else {
          console.log("查询失败");
        }
      });
    }
  }
};
// 订单和兑换的审核
</script>

<style lang="scss" scoped>
// 订单列表
.orderContainer {
  .option {
    padding: 10px;
    .search {
      float: right;
      padding: 10px;
    }
  }
  .row {
    padding: 10px;
    .rowTil {
      display: block;
      padding: 10px 0;
    }
  }
}
</style>

<style>
.orderContainer .el-button--success {
  margin-left: 10px !important;
}
</style>

